<template>
  <div>
    <el-dialog
      title="查看商品品牌"
      :visible.sync="dialog.GoodsBrandMainShow"
      width="80%"
      append-to-body
    >
      <GoodsBrandMain
        ref="GoodsBrandMainShow"
        :isMultiple="true"
        :multipleOptions="{optType: 'show'}"
        @showSelectDialog="showSelectDialog"
        @refresh="refresh"
      />
    </el-dialog>
    <el-dialog
      title="新增商品品牌"
      :visible.sync="dialog.GoodsBrandMainAdd"
      width="80%"
      append-to-body
    >
      <GoodsBrandMain
        ref="GoodsBrandMainAdd"
        :isMultiple="true"
        :multipleOptions="{optType: 'add'}"
        @closeSelectDialog="closeSelectDialog"
        @refresh="refresh"
      />
    </el-dialog>
  </div>
</template>

<script>
import { doPostJson } from '@/utils/utils'
import * as ResponseStatus from '@/utils/response-status'
import GoodsBrandMain from '../GoodsBrand/GoodsBrandMain.vue'
export default {
  name: 'GoodsCategoryBrandDialog',
  components: {
    GoodsBrandMain
  },
  data() {
    return {
      dialog: {
        GoodsBrandMainShow: false,
        GoodsBrandMainAdd: false
      },
      category: {},
      selectedData: []
    }
  },
  computed: {},
  mounted() {},
  methods: {
    initData(category) {
      this.category = category
      this.dialog.GoodsBrandMainShow = true
      this.$nextTick(() => {
        let goodsBrandMainShow = this.$refs.GoodsBrandMainShow
        goodsBrandMainShow.extraData = category
        doPostJson(
        '/goods-category-brand/admin/all-cond',
        {
          categoryId: this.category.id,
          isActive: 1
        },
        {}
      )
        .then(res => {
          let brandIds = [0]
          res.data.rows.forEach(row => {
            brandIds.push(row.brandId)
          })
          goodsBrandMainShow.resetSearchExcludeProps = ['ids']
          goodsBrandMainShow.$refs.searchDialog.searchForm.ids = brandIds
          goodsBrandMainShow.$refs.quickSearch.searchForm.ids = brandIds
          goodsBrandMainShow.searchTable(false, true)
          this.selectedData = res.data.rows
        })
        .catch(err => {})
      })
    },
    showSelectDialog() {
      this.dialog.GoodsBrandMainAdd = true
      this.$nextTick(() => {
        let goodsBrandMainAdd = this.$refs.GoodsBrandMainAdd
        let goodsBrandTable = goodsBrandMainAdd.$refs.table
        goodsBrandTable.selectedData = this.selectedData
        goodsBrandTable.selectedDataIdProp = 'brandId'
        goodsBrandTable.extraData.categoryId = this.category.id
        goodsBrandTable.extraData.categoryTitle = this.category.title
        goodsBrandMainAdd.searchTable(false, true)
      })
    },
    closeSelectDialog() {
      this.dialog.GoodsBrandMainAdd = false
    },
    refresh() {
      this.initData(this.category)
    }
  }
}
</script>

<style>
</style>
